
import { HEADER,URL } from './../config.js';
/**
 * 发送请求
 */
export default function request(api, method, data, { noAuth = false, noVerify = false }) {
	
  let Url = URL, header = HEADER;


  if (getApp().globalData.token){
	  header['Authori-zation'] = 'Bearer ' + getApp().globalData.token;
  }
  console.log('请求url:',Url  + api)
  console.log('请求method:',method || 'GET')
  console.log('请求header:',header)
  console.log('请求data:',data || {})

  return new Promise((reslove, reject) => {

    uni.request({
      url: Url  + api,
      method: method || 'GET',
      header: header,
      data: data || {},
      success: (res) => {
		  reslove(res)
      },
      fail: (msg) => {
        reject(msg);
      }
    })
  });
}

['options', 'get', 'post', 'put', 'head', 'delete', 'trace', 'connect'].forEach((method) => {
  request[method] = (api, data, opt) => request(api, method, data, opt || {})
});